home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / +look_here_1st!+ / reader_requests / alienbreed3d2 / cheesesauce / objectmoveb < prev    next >
Text File  |  1997-11-28  |  29KB  |  2,107 lines

  1. extlen: dc.w 0
  2. awayfromwall: dc.w 0
  3. wallbounce: dc.w 0
  4. wallxsize: dc.w 0
  5. wallzsize: dc.w 0
  6. walllength: dc.w 0
  7.  
  8. RoomPath: ds.w 100
  9. RoomPathPtr: dc.l 0
  10.  
  11. MoveObject:
  12.  
  13.  move.l #RoomPath,RoomPathPtr
  14.  
  15.  clr.b hitwall
  16.  
  17.  move.w newx,d0
  18.  sub.w oldx,d0
  19.  move.w d0,xdiff
  20.  move.w newz,d0
  21.  sub.w oldz,d0
  22.  move.w d0,zdiff
  23.  
  24.  move.l newy,wallhitheight
  25.  move.l objroom,a0
  26.  
  27. gobackanddoitallagain:
  28.  
  29.  move.l a0,a5
  30.  adda.w ToExitList(a5),a0
  31.  move.l a0,test
  32.  move.l FloorLines,a1
  33. checkwalls:
  34.  move.w (a0)+,d0
  35.  blt nomorewalls
  36.  
  37.  asl.w #4,d0
  38.  lea (a1,d0.w),a2
  39.  
  40. *********************************
  41. * Check if we are within exit limits
  42. * of zone.
  43. *********************************
  44.  
  45.  move.l #-65536*256,d0
  46.  move.l d0,LowerRoofHeight
  47.  move.l d0,UpperRoofHeight
  48.  move.l d0,LowerFloorHeight
  49.  move.l d0,UpperFloorHeight
  50.  
  51. ; tst.b 9(a2)
  52. ; bne thisisawall2
  53.  
  54.  moveq #0,d1
  55.  move.w 8(a2),d1
  56.  blt thisisawall2
  57.  move.l ZoneAdds,a4
  58.  move.l (a4,d1.w*4),a4
  59.  add.l LEVELDATA,a4
  60.  
  61.  move.l ToZoneFloor(a4),d1
  62.  move.l d1,LowerFloorHeight
  63.  move.l ToZoneRoof(a4),d2
  64.  move.l d2,LowerRoofHeight
  65.  sub.l d2,d1
  66.  cmp.l thingheight,d1
  67.  ble thisisawall1
  68.  
  69.  move.l oldy,d0
  70.  move.l d0,d1
  71.  add.l thingheight,d1
  72.  sub.l ToZoneFloor(a4),d1
  73.  bgt.s chkstepup
  74.  
  75.  neg.l d1
  76.  cmp.l StepDownVal,d1
  77.  blt.s botinsidebot
  78.  
  79. chkstepup:
  80.  cmp.l StepUpVal,d1
  81.  blt.s botinsidebot
  82.  
  83. ; We have a wall!
  84.  bra thisisawall1
  85.  
  86. botinsidebot:
  87.  
  88.  sub.l ToZoneRoof(a4),d0
  89.  blt.s thisisawall1
  90.  
  91.  bra checkwalls
  92.  
  93. thisisawall1:
  94.  
  95.  move.l ToUpperFloor(a4),d1
  96.  move.l d1,UpperFloorHeight
  97.  move.l ToUpperRoof(a4),d2
  98.  sub.l d2,d1
  99.  move.l d2,UpperRoofHeight
  100.  cmp.l thingheight,d1
  101.  ble thisisawall2
  102.  
  103.  move.l oldy,d0
  104.  move.l d0,d1
  105.  add.l thingheight,d1
  106.  sub.l ToUpperFloor(a4),d1
  107.  bgt.s chkstepup2
  108.  
  109.  neg.l d1
  110.  cmp.l StepDownVal,d1
  111.  blt.s botinsidebot2
  112.  bra.s thisisawall2
  113.  
  114. chkstepup2:
  115.  cmp.l StepUpVal,d1
  116.  blt.s botinsidebot2
  117.  
  118. ; We have a wall!
  119.  bra thisisawall2
  120.  
  121. botinsidebot2:
  122.  
  123.  sub.l ToUpperRoof(a4),d0
  124.  blt.s thisisawall2
  125.  
  126.  bra checkwalls
  127. thisisawall2
  128.  
  129.  move.l #0,a4
  130.  move.l #0,a6
  131.  move.b awayfromwall,d3
  132.  blt.s .notomatoes
  133.  
  134.  move.b 12(a2),d2
  135.  ext.w d2
  136.  
  137.  move.b 13(a2),d4
  138.  ext.w d4
  139.  
  140.  tst.b d3
  141.  beq.s .noshift
  142.  asl.w d3,d2
  143.  asl.w d3,d4
  144. .noshift
  145.  
  146.  move.w d2,a4
  147.  move.w d4,a6
  148.  
  149. .notomatoes:
  150.  
  151.  move.w newx,d0
  152.  move.w newz,d1
  153.  sub.w (a2),d0
  154.  sub.w 2(a2),d1
  155.  sub.w a4,d0
  156.  sub.w a6,d1
  157.  
  158.  move.w 4(a2),d2
  159.  sub.w a4,d2
  160.  sub.w a6,d2
  161.  
  162.  muls d2,d1
  163.  
  164.  move.w 6(a2),d5
  165.  add.w a4,d5
  166.  sub.w a6,d5
  167.  
  168.  muls d5,d0
  169.  sub.l d1,d0
  170.  blt chkhttt
  171.  
  172.  move.w 10(a2),d3
  173.  add.w extlen,d3
  174.  divs d3,d0
  175.  cmp.w #32,d0
  176.  bge oknothitwall
  177.  
  178.  move.w wallflags(pc),d0
  179.  or.w d0,14(a2) 
  180.  
  181.  bra oknothitwall
  182.  
  183. chkhttt:
  184.  
  185.  move.w d2,WALLXLEN
  186.  move.w d5,WALLZLEN
  187.  
  188.  move.l d0,d7
  189.  
  190.  move.w 10(a2),d3
  191.  add.w extlen,d3
  192.  divs d3,d7    ;  d
  193.  
  194.  move.l newy,d4
  195.  sub.l oldy,d4
  196. ; beq .dontworryhit
  197.  
  198.  move.w oldx,d0
  199.  move.w oldz,d1
  200.  sub.w (a2),d0
  201.  sub.w 2(a2),d1
  202.  sub.w a4,d0
  203.  sub.w a6,d1
  204.  
  205.  muls d2,d1
  206.  muls d5,d0
  207.  sub.l d1,d0
  208.  divs d3,d0    ; otherd
  209.  
  210.  sub.w d7,d0    ; total distance travelled across wall
  211.  bgt.s .ohbugger
  212.  moveq #1,d0
  213. .ohbugger:
  214.  
  215. ; We now have ratio to multiply x,z and y differences
  216. ; by. Check y=0 since that's quite common.
  217.  
  218.  move.l d4,d1
  219.  beq.s .dontworryhit
  220.  
  221.  divs d0,d1
  222.  muls d7,d1
  223. .dontworryhit:
  224.  add.l newy,d1 ; height at point of crossing wall.
  225.  move.l d1,d6
  226.  add.l thingheight,d6
  227.  
  228.  cmp.l LowerFloorHeight,d6
  229.  bge.s .yeshit
  230.  cmp.l LowerRoofHeight,d1
  231.  bgt oknothitwall
  232.  cmp.l UpperRoofHeight,d1
  233.  blt.s .yeshit
  234.  cmp.l UpperFloorHeight,d6
  235.  blt oknothitwall
  236.  
  237. .yeshit:
  238.  
  239.  move.l d1,wallhitheight
  240.  
  241.  tst.b wallbounce
  242.  bne.s .calcbounce
  243.  
  244.  tst.b exitfirst(pc)
  245.  beq.s .calcalong
  246.  bne.s .calcwherehit
  247.  
  248. .calcbounce:
  249.  
  250. ; For simplicity (possibility!) the
  251. ; bounce routine will:
  252. ; Place the object at wall contact
  253. ; point
  254. ; Supply wall data to reflect the
  255. ; movement direction of the object
  256.  
  257.  move.w d2,wallxsize
  258.  move.w d5,wallzsize
  259.  move.w d3,walllength
  260.  
  261. .calcwherehit:
  262.  
  263. ; add.w #20,d7
  264.  move.w newx,d6
  265.  sub.w oldx,d6
  266.  muls d7,d6
  267.  divs d0,d6
  268.  add.w newx,d6
  269.  
  270.  move.w newz,d1
  271.  sub.w oldz,d1
  272.  muls d7,d1
  273.  divs d0,d1
  274.  add.w newz,d1
  275.  move.w d6,d0
  276.  move.w d1,d7
  277.  bra.s .calcedhit
  278.  
  279. .calcalong:
  280.  
  281. ; sub.w #3,d7
  282.  move.w d7,d6
  283.  muls d5,d6
  284.  muls d2,d7
  285.  divs d3,d6
  286.  divs d3,d7
  287.  neg.w d6
  288.  add.w newx,d6    ; point on wall
  289.  add.w newz,d7
  290.  
  291.  move.w d6,d0
  292.  move.w d7,d1
  293. ; bra.s othercheck
  294.  
  295. .calcedhit:
  296.  
  297.  move.w newx,d6
  298.  move.w newz,d7
  299.  sub.w oldx,d6
  300.  sub.w oldz,d7
  301.   
  302.  move.w (a2),d4
  303.  add.w a4,d4
  304.  sub.w oldx,d4
  305.  muls d4,d7; negative if on left
  306.  move.w 2(a2),d4
  307.  add.w a6,d4
  308.  sub.w oldz,d4
  309.  muls d4,d6
  310.  sub.l d6,d7
  311.  bgt oknothitwall
  312.  
  313.  move.w d0,d6
  314.  move.w d1,d7
  315.  move.w newx,d6
  316.  move.w newz,d7
  317.  sub.w oldx,d6
  318.  sub.w oldz,d7
  319.  
  320.  move.w (a2),d4
  321.  sub.w a4,d4
  322.  add.w d2,d4
  323.  sub.w oldx,d4
  324.  muls d4,d7; negative if on left
  325.  move.w 2(a2),d4
  326.  sub.w a6,d4
  327.  add.w d5,d4
  328.  sub.w oldz,d4
  329.  muls d4,d6
  330.  sub.l d6,d7
  331.  blt oknothitwall
  332.  bra hitthewall
  333.  
  334.  
  335. othercheck:
  336.  
  337. ; sub.w (a2),d6
  338. ; sub.w 2(a2),d7
  339. ; sub.w a4,d6
  340. ; sub.w a6,d7
  341. ; muls d6,d6
  342. ; muls d7,d7
  343. ; add.w #5,d3
  344. ; muls d3,d3
  345. ; add.l d6,d7
  346. ; cmp.l d3,d7
  347. ; bgt oknothitwall
  348. ; move.w d1,d7
  349. ; move.w d0,d6
  350. ; sub.w (a2),d6
  351. ; sub.w 2(a2),d7
  352. ; sub.w d2,d6
  353. ; sub.w d5,d7
  354. ; muls d6,d6
  355. ; muls d7,d7
  356. ; add.l d6,d7
  357. ; cmp.l d3,d7
  358. ; bgt oknothitwall
  359. ;************8 
  360.  
  361.  sub.w (a2),d6
  362.  sub.w 2(a2),d7
  363.  
  364.  sub.w a4,d6
  365.  sub.w a6,d7
  366.  move.w d2,d4
  367.  bge.s okplus1
  368.  neg.w d4
  369. okplus1
  370.  move.w d5,d3
  371.  bge.s okplus2
  372.  neg.w d3
  373. okplus2:
  374.  cmp.w d4,d3
  375.  bgt.s UseZ
  376.  
  377. ; Use the x coord!
  378.  
  379.  tst.w d6
  380.  bgt.s xispos
  381.  
  382.  move.w d2,d7
  383.  cmp.w #4,d7
  384.  bgt.s oknothitwall
  385.  sub.w #4,d7
  386.  cmp.w d7,d6
  387.  blt.s oknothitwall
  388.  
  389.  bra.s hitthewall
  390.  
  391. xispos:
  392.  
  393.  move.w d2,d7
  394.  cmp.w #-4,d7
  395.  blt.s oknothitwall
  396.  add.w #4,d7
  397.  cmp.w d7,d6
  398.  bgt.s oknothitwall
  399.  
  400.  bra.s hitthewall
  401.  
  402. UseZ:
  403.  tst.w d7
  404.  bgt.s zispos
  405.  
  406.  move.w d5,d6
  407.  cmp.w #4,d6
  408.  bgt.s oknothitwall
  409.  sub.w #4,d6
  410.  cmp.w d6,d7
  411.  blt.s oknothitwall
  412.  
  413.  bra.s hitthewall
  414.  
  415. zispos:
  416.  
  417.  move.w d5,d6
  418.  cmp.w #-4,d6
  419.  blt.s oknothitwall
  420.  add.w #4,d6
  421.  cmp.w d6,d7
  422.  bgt.s oknothitwall 
  423.  
  424. hitthewall:
  425.  
  426.  move.w d0,newx
  427.  move.w d1,newz
  428.  move.w wallflags(pc),d0
  429.  or.w d0,14(a2)
  430.  st hitwall
  431.  tst.b exitfirst(pc)
  432.  bne stopandleave
  433.  
  434. oknothitwall:
  435.  
  436.  bra checkwalls
  437. nomorewalls:
  438.  
  439.  tst.w extlen
  440.  beq NOOTHERWALLSNEEDED
  441.  
  442.  tst.w xdiff
  443.  bne.s notstill
  444.  tst.w zdiff
  445.  bne.s notstill
  446.  move.l objroom,a0
  447.  bra mustbeinsameroom
  448. notstill:
  449.  
  450.  move.l a5,a0
  451.  add.w ToExitList(a0),a0
  452.  
  453. checkotherwalls:
  454.  move.w (a0)+,d0
  455.  bge anotherwalls
  456.  cmp.w #-2,d0
  457.  beq nomoreotherwalls
  458.  bra checkotherwalls
  459.  
  460. anotherwalls:
  461.  
  462.  asl.w #4,d0
  463.  lea (a1,d0.w),a2
  464.  
  465. *********************************
  466. * Check if we are within exit limits
  467. * of zone.
  468. *********************************
  469.  
  470. ; tst.b 9(a2)
  471. ; bne .thisisawall2
  472.  
  473.  moveq #0,d1
  474.  move.w 8(a2),d1
  475.  blt .thisisawall2
  476.  move.l ZoneAdds,a4
  477.  move.l (a4,d1.w*4),a4
  478.  add.l LEVELDATA,a4
  479.  
  480.  move.l ToZoneFloor(a4),d1
  481.  sub.l ToZoneRoof(a4),d1
  482.  cmp.l thingheight,d1
  483.  ble .thisisawall1
  484.  
  485.  move.l newy,d0
  486.  move.l d0,d1
  487.  add.l thingheight,d1
  488.  sub.l ToZoneFloor(a4),d1
  489.  bgt.s .chkstepup
  490.  
  491.  neg.l d1
  492.  cmp.l StepDownVal,d1
  493.  blt.s .botinsidebot
  494.  bra.s .thisisawall1
  495.  
  496. .chkstepup:
  497.  
  498.  cmp.l StepUpVal,d1
  499.  blt.s .botinsidebot
  500.  
  501. ; We have a wall!
  502.  bra .thisisawall1
  503.  
  504. .botinsidebot:
  505.  
  506.  sub.l ToZoneRoof(a4),d0
  507.  blt.s .thisisawall1
  508.  
  509.  bra checkotherwalls
  510.  
  511. .thisisawall1:
  512.  
  513.  move.l ToUpperFloor(a4),d1
  514.  sub.l ToUpperRoof(a4),d1
  515.  cmp.l thingheight,d1
  516.  ble .thisisawall2
  517.  
  518.  move.l newy,d0
  519.  move.l d0,d1
  520.  add.l thingheight,d1
  521.  sub.l ToUpperFloor(a4),d1
  522.  bgt.s .chkstepup2
  523.  
  524.  neg.l d1
  525.  cmp.l StepDownVal,d1
  526.  blt.s .botinsidebot2
  527.  bra.s .thisisawall2
  528.  
  529. .chkstepup2:
  530.  
  531.  cmp.l StepUpVal,d1
  532.  blt.s .botinsidebot2
  533.  
  534. ; We have a wall!
  535.  bra .thisisawall2
  536.  
  537. .botinsidebot2:
  538.  
  539.  sub.l ToUpperRoof(a4),d0
  540.  blt.s .thisisawall2
  541.  
  542.  bra checkotherwalls
  543.  
  544. .thisisawall2:
  545.  
  546.  move.l #0,a4
  547.  move.l #0,a6
  548.  move.b awayfromwall,d3
  549.  blt.s .notomatoes
  550.  
  551.  move.b 12(a2),d2
  552.  ext.w d2
  553.  
  554.  move.b 13(a2),d4
  555.  ext.w d4
  556.  
  557.  tst.b d3
  558.  beq.s .noshift
  559.  asl.w d3,d2
  560.  asl.w d3,d4
  561. .noshift
  562.  
  563.  move.w d2,a4
  564.  move.w d4,a6
  565.  
  566. .notomatoes:
  567.  
  568.  move.w 4(a2),d2
  569.  sub.w a4,d2
  570.  sub.w a6,d2
  571.  move.w d2,DX
  572.  move.w 6(a2),d5
  573.  add.w a4,d5
  574.  sub.w a6,d5
  575.  
  576.  
  577.  move.w newx,d0
  578.  move.w newz,d1
  579.  sub.w (a2),d0
  580.  sub.w 2(a2),d1
  581.  sub.w a4,d0
  582.  sub.w a6,d1
  583.  muls DX,d1
  584.  muls d5,d0
  585.  sub.l d1,d0
  586.  bge .oknothitwall
  587.  move.l d0,d7
  588.  
  589.  move.w oldx,d1
  590.  move.w newx,d3
  591.  sub.w d1,d3
  592.  sub.w (a2),d1
  593.  sub.w a4,d1 ;e-a=d1
  594.  
  595.  move.w 2(a2),d2
  596.  add.w a6,d2
  597.  sub.w oldz,d2    ;b-f=d2
  598.  
  599.  move.w newz,d4
  600.  sub.w oldz,d4
  601.  
  602.  muls d4,d1
  603.  muls d3,d2
  604.  add.l d2,d1    ; h(e-a)+g(b-f)
  605.  
  606.  muls DX,d4
  607.  muls d5,d3
  608.  sub.l d3,d4
  609.  beq .oknothitwall
  610.  bgt.s .botpos
  611. .botneg:
  612.  tst.l d1
  613.  bgt .oknothitwall
  614.  cmp.l d1,d4
  615.  ble .mighthit
  616.  bra .oknothitwall
  617.  
  618. .botpos:
  619.  tst.l d1
  620.  blt .oknothitwall
  621.  cmp.l d1,d4
  622.  blt .oknothitwall
  623.  
  624. .mighthit:
  625.  
  626.  move.w 10(a2),d0
  627.  add.w extlen,d0
  628.  divs d0,d7    ;  d
  629.  sub.w #3,d7
  630.  move.w d7,d6
  631.  muls d5,d6
  632.  muls DX,d7
  633.  divs d0,d6
  634.  divs d0,d7
  635.  neg.w d6
  636.  add.w newx,d6    ; point on wall
  637.  add.w newz,d7
  638.  
  639.  move.w oldx,d0
  640.  move.w oldz,d1
  641.  sub.w (a2),d0
  642.  sub.w 2(a2),d1
  643.  sub.w a4,d0
  644.  sub.w a6,d1
  645.  muls DX,d1
  646.  muls d5,d0
  647.  sub.l d1,d0
  648.  blt .oknothitwall
  649.  
  650.  move.w d6,d0
  651.  move.w d7,d1
  652.  
  653.  bra .hitthewall
  654.  
  655.  sub.w (a2),d6
  656.  sub.w 2(a2),d7
  657.  move.w d6,d4
  658.  bge.s .okplus1
  659.  neg.w d4
  660. .okplus1
  661.  move.w d7,d3
  662.  bge.s .okplus2
  663.  neg.w d3
  664. .okplus2:
  665.  cmp.w d4,d3
  666.  bgt.s .UseZ
  667.  
  668. ; Use the x coord!
  669.  
  670.  tst.w d6
  671.  bgt.s .xispos
  672.  
  673.  move.w DX,d7
  674.  bgt.s .oknothitwall
  675.  cmp.w d7,d6
  676.  blt.s .oknothitwall
  677.  
  678.  bra.s .hitthewall
  679.  
  680. .xispos:
  681.  
  682.  move.w DX,d7
  683.  blt.s .oknothitwall
  684.  cmp.w d7,d6
  685.  bgt.s .oknothitwall
  686.  
  687.  bra.s .hitthewall
  688.  
  689. .UseZ:
  690.  tst.w d7
  691.  bgt.s .zispos
  692.  
  693.  move.w d5,d6
  694.  bgt.s .oknothitwall
  695.  cmp.w d6,d7
  696.  blt.s .oknothitwall
  697.  
  698.  bra.s .hitthewall
  699.  
  700. .zispos:
  701.  
  702.  move.w d5,d6
  703.  blt.s .oknothitwall
  704.  cmp.w d6,d7
  705.  bgt.s .oknothitwall
  706.  
  707.  
  708. .hitthewall:
  709.  
  710.  move.w d0,newx
  711.  move.w d1,newz
  712.  move.w wallflags(pc),d0
  713.  or.w d0,14(a2)
  714.  st hitwall
  715.  tst.b exitfirst(pc)
  716.  bne stopandleave
  717.  
  718. .oknothitwall:
  719.  
  720.  bra checkotherwalls
  721. nomoreotherwalls:
  722.  
  723. NOOTHERWALLSNEEDED
  724.  
  725.  
  726. ; move.w xdiff,d2
  727. ; muls d2,d2
  728. ; move.w zdiff,d3
  729. ; muls d3,d3
  730. ; move.w #0,movespd
  731. ; move.l #0,largespd
  732. ; add.l d3,d2
  733. ;
  734. ; move.w #31,d0
  735. ;.findhigh
  736. ; btst d0,d2
  737. ; bne .foundhigh
  738. ; dbra d0,.findhigh
  739. ;.foundhigh
  740. ; asr.w #1,d0
  741. ; clr.l d3
  742. ; bset d0,d3
  743. ; move.l d3,d0
  744. ;
  745. ; move.w d0,d3
  746. ; muls d3,d3    ; x*x
  747. ; sub.l d2,d3    ; x*x-a
  748. ; asr.l #1,d3    ; (x*x-a)/2
  749. ; divs d0,d3    ; (x*x-a)/2x
  750. ; sub.w d3,d0    ; second approx
  751. ; bgt .stillnot0
  752. ; move.w #1,d0
  753. ;.stillnot0
  754. ;
  755. ; move.w d0,d3
  756. ; muls d3,d3
  757. ; sub.l d2,d3
  758. ; asr.l #1,d3
  759. ; divs d0,d3
  760. ; sub.w d3,d0    ; second approx
  761. ; bgt .stillnot02
  762. ; move.w #1,d0
  763. ;.stillnot02
  764. ;
  765. ; move.w d0,movespd
  766. ;.moving
  767. ; ext.l d0
  768. ; asl.l #5,d0
  769. ; move.l d0,largespd
  770.  
  771. *****************************************************
  772. * FIND ROOM WE'RE STANDING IN ***********************
  773. *****************************************************
  774.  
  775.  move.l a5,a0
  776.  adda.w ToExitList(a5),a0
  777.  
  778.  move.l FloorLines,a1
  779. CheckMoreFloorLines
  780.  move.w (a0)+,d0    ; Either a floor line or -1
  781.  blt NoMoreFloorLines
  782.  asl.w #4,d0
  783.  lea (a1,d0.w),a2
  784.  
  785.  tst.w 8(a2)
  786.  blt.s CheckMoreFloorLines
  787.  
  788.  clr.b CrossIntoTop
  789.  
  790.  moveq #0,d1
  791.  move.w 8(a2),d1
  792.  move.l ZoneAdds,a4
  793.  move.l (a4,d1.w*4),a4
  794.  add.l LEVELDATA,a4
  795.  
  796.  move.l newy,d0
  797.  move.l d0,d1
  798.  add.l thingheight,d1
  799.  
  800.  sub.l ToZoneRoof(a4),d0
  801.  blt.s NOTINLOWER
  802.  
  803.  sub.l ToZoneFloor(a4),d1
  804.  blt.s okthebottom
  805.  
  806.  cmp.l StepUpVal,d1
  807.  bgt.s NOTINLOWER
  808.  
  809. ; move.l ToZoneFloor(a4),d1
  810. ; sub.l thingheight,d1
  811. ; move.l d1,newy
  812.  bra okthebottom
  813.  
  814. NOTINLOWER:
  815.  
  816.  move.l ToZoneRoof(a4),billy
  817.  move.l ToZoneRoof(a4),billy+4
  818.  add.l d0,billy+4
  819.  
  820.  st CrossIntoTop
  821.  move.l newy,d0
  822.  move.l d0,d1
  823.  add.l thingheight,d1
  824.  sub.l ToUpperRoof(a4),d0
  825.  blt CheckMoreFloorLines
  826.  
  827.  sub.l ToUpperFloor(a4),d1
  828.  blt.s okthebottom
  829.  
  830.  cmp.l StepUpVal,d1
  831.  bgt CheckMoreFloorLines
  832.  
  833. ; move.l ToUpperFloor(a4),d1
  834. ; sub.l thingheight,d1
  835. ; move.l d1,newy
  836.  
  837. okthebottom
  838.  
  839.  move.w newx,d0
  840.  move.w newz,d1
  841.  sub.w (a2),d0    ;a
  842.  sub.w 2(a2),d1    ;b
  843.  muls 4(a2),d1
  844.  muls 6(a2),d0
  845.  moveq #0,d3
  846.  move.w 8(a2),d3
  847.  move.l ZoneAdds,a3
  848.  move.l (a3,d3.w*4),a3
  849.  add.l LEVELDATA,a3
  850.  sub.l d1,d0
  851.  bge StillSameSide
  852.  
  853. * Player is now on the left side of this line.
  854. * Where was he before?
  855.  
  856. ; cmp.l a4,a5
  857. ; bne StillSameSide
  858.  
  859. ; move.w oldx,d0
  860. ; move.w oldz,d1
  861. ; sub.w (a2),d0    ;a
  862. ; sub.w 2(a2),d1    ;b
  863. ; muls 4(a2),d1
  864. ; muls 6(a2),d0
  865. ; sub.l d1,d0
  866. ; blt StillSameSide
  867. ; bra checkifcrossed
  868.  
  869. OnRightsideofline:
  870. * Player is now on the right side of the line.
  871. * Where was he last time?
  872.  
  873. ; exg a3,a4
  874.  
  875. ; cmp.l a3,a5
  876. ; bne StillSameSide
  877.  
  878. ; move.w oldx,d0
  879. ; move.w oldz,d1
  880. ; sub.w (a2),d0    ;a
  881. ; sub.w 2(a2),d1    ;b
  882. ; muls 4(a2),d1
  883. ; muls 6(a2),d0
  884. ; sub.l d1,d0
  885. ; bgt StillSameSide
  886.  
  887. checkifcrossed:
  888.  
  889. *Player used to be on other side of this line.
  890. *Need to check if he crossed it.
  891.  
  892.  move.w newx,d6
  893.  move.w newz,d7
  894.  sub.w oldx,d6
  895.  sub.w oldz,d7
  896.   
  897.  move.w (a2),d4
  898.  add.w a4,d4
  899.  sub.w oldx,d4
  900.  muls d4,d7; negative if on left
  901.  move.w 2(a2),d4
  902.  add.w a6,d4
  903.  sub.w oldz,d4
  904.  muls d4,d6
  905.  sub.l d6,d7
  906.  bgt StillSameSide
  907.  
  908.  move.w d0,d6
  909.  move.w d1,d7
  910.  move.w newx,d6
  911.  move.w newz,d7
  912.  sub.w oldx,d6
  913.  sub.w oldz,d7
  914.  
  915.  move.w (a2),d4
  916.  sub.w a4,d4
  917.  add.w d2,d4
  918.  sub.w oldx,d4
  919.  muls d4,d7; negative if on left
  920.  move.w 2(a2),d4
  921.  sub.w a6,d4
  922.  add.w d5,d4
  923.  sub.w oldz,d4
  924.  muls d4,d6
  925.  sub.l d6,d7
  926.  blt StillSameSide
  927.  
  928.  move.l a3,a5
  929.  move.l RoomPathPtr,a0
  930.  move.w (a3),(a0)+
  931.  move.l a0,RoomPathPtr
  932.  move.l a3,a0
  933.  move.b CrossIntoTop,StoodInTop
  934.  
  935.  bra gobackanddoitallagain
  936.  bra.s donefloorline
  937.  
  938. StillSameSide:
  939. donefloorline:
  940.  
  941.  bra CheckMoreFloorLines
  942. NoMoreFloorLines:
  943.  
  944.  move.l a5,a0
  945.  move.l a5,objroom
  946.  
  947. mustbeinsameroom:
  948.  
  949. stopandleave:
  950.  
  951.  move.l RoomPathPtr,a0
  952.  move.w #-1,(a0)+
  953.  
  954.  rts
  955.  
  956.  
  957. DX: dc.w 0
  958.  
  959. tstxval: dc.l 0
  960. oldx: dc.l 0
  961. oldz: dc.l 0
  962. newx: dc.l 0
  963. newz: dc.l 0
  964. xdiff: dc.l 0
  965. zdiff: dc.l 0
  966. objroom: dc.l 0
  967. hitwall: dc.b 0
  968. exitfirst: dc.b 0
  969. speed: dc.w 0
  970. wallflags: dc.w 0
  971. distaway: dc.w 0
  972. newy: dc.l 0
  973. oldy: dc.l 0
  974. thingheight: dc.l 0
  975. StepUpVal: dc.l 0
  976. StepDownVal: dc.l 0
  977. wallhitheight: dc.l 0
  978. seclot: dc.b 0
  979.  
  980.  even
  981. WALLXLEN: dc.w 0
  982. WALLZLEN: dc.w 0
  983. onwallx: dc.w 0
  984. onwallz: dc.w 0
  985. slidex: dc.w 0
  986. slidez: dc.w 0
  987. CrossIntoTop: dc.b 0
  988. StoodInTop: dc.b 0
  989. LowerFloorHeight: dc.l 0
  990. LowerRoofHeight: dc.l 0
  991. UpperFloorHeight: dc.l 0
  992. UpperRoofHeight: dc.l 0
  993.  
  994. billy: dc.l 0,0
  995.  
  996.  even
  997.  
  998. HeadTowards:
  999.  
  1000.  move.w newx,d1
  1001.  sub.w oldx,d1
  1002.  move.w d1,xdiff
  1003.  move.w newz,d2
  1004.  sub.w oldz,d2
  1005.  move.w d2,zdiff
  1006.  muls d1,d1
  1007.  muls d2,d2
  1008.  move.w #0,d0
  1009.  move.w d0,distaway
  1010.  add.l d1,d2
  1011.  beq nochange
  1012.  
  1013.  move.w #31,d0
  1014. .findhigh
  1015.  btst d0,d2
  1016.  bne .foundhigh
  1017.  dbra d0,.findhigh
  1018. .foundhigh
  1019.  asr.w #1,d0
  1020.  clr.l d3
  1021.  bset d0,d3
  1022.  move.l d3,d0
  1023.  
  1024.  move.w d0,d1
  1025.  muls d1,d1    ; x*x
  1026.  sub.l d2,d1    ; x*x-a
  1027.  asr.l #1,d1    ; (x*x-a)/2
  1028.  divs d0,d1    ; (x*x-a)/2x
  1029.  sub.w d1,d0    ; second approx
  1030.  bgt .stillnot0
  1031.  move.w #1,d0
  1032. .stillnot0
  1033.  
  1034.  move.w d0,d1
  1035.  muls d1,d1
  1036.  sub.l d2,d1
  1037.  asr.l #1,d1
  1038.  divs d0,d1
  1039.  sub.w d1,d0    ; second approx
  1040.  bgt .stillnot02
  1041.  move.w #1,d0
  1042. .stillnot02
  1043.  
  1044.  move.w d0,distaway
  1045.  
  1046. ; d0=perpdist
  1047.  
  1048.  cmp.w Range,d0
  1049.  sle GotThere
  1050.  bgt.s faraway
  1051.  
  1052.  move.w xdiff,d1
  1053.  move.w zdiff,d2
  1054.  muls Range,d1
  1055.  muls Range,d2
  1056.  divs d0,d1
  1057.  divs d0,d2
  1058.  neg.w d1
  1059.  neg.w d2
  1060.  add.w d1,newx
  1061.  add.w d2,newz
  1062.  tst.b canshove
  1063.  beq nochange
  1064.  move.w PLR1_opushx(pc),d1
  1065.  add.w PLR2_opushx(pc),d1
  1066.  sub.w d1,newx
  1067.  move.w PLR1_opushz(pc),d1
  1068.  add.w PLR2_opushz(pc),d1
  1069.  sub.w d1,newz
  1070.  move.w xdiff,d1
  1071.  move.w zdiff,d2
  1072.  move.w Range,d3
  1073.  sub.w d0,d3
  1074.  muls d3,d1
  1075.  muls d3,d2
  1076.  divs d0,d1
  1077.  divs d0,d2
  1078.  move.w d1,shovex
  1079.  move.w d2,shovez
  1080.  bra nochange
  1081.  
  1082. faraway:
  1083.  move.w speed,d3
  1084.  add.w Range,d3
  1085.  cmp.w d0,d3
  1086.  blt.s .notoofast
  1087.  move.w d0,d3
  1088.  st GotThere
  1089. .notoofast:
  1090.  sub.w Range,d3
  1091.  
  1092.  move.w xdiff,d1
  1093.  muls d3,d1
  1094.  divs d0,d1
  1095.  move.w zdiff,d2
  1096.  muls d3,d2
  1097.  divs d0,d2
  1098.  add.w oldx,d1
  1099.  move.w d1,newx
  1100.  add.w oldz,d2
  1101.  move.w d2,newz
  1102.  
  1103. nochange:
  1104.  
  1105.  rts
  1106.  
  1107.  
  1108. CalcDist:
  1109.  
  1110.  move.w newx,d1
  1111.  sub.w oldx,d1
  1112.  move.w d1,xdiff
  1113.  move.w newz,d2
  1114.  sub.w oldz,d2
  1115.  move.w d2,zdiff
  1116.  muls d1,d1
  1117.  muls d2,d2
  1118.  move.w #0,d0
  1119.  move.w d0,distaway
  1120.  add.l d1,d2
  1121.  beq .nochange
  1122.  
  1123.  move.w #31,d0
  1124. .findhigh
  1125.  btst d0,d2
  1126.  bne .foundhigh
  1127.  dbra d0,.findhigh
  1128. .foundhigh
  1129.  asr.w #1,d0
  1130.  clr.l d3
  1131.  bset d0,d3
  1132.  move.l d3,d0
  1133.  
  1134.  move.w d0,d1
  1135.  muls d1,d1    ; x*x
  1136.  sub.l d2,d1    ; x*x-a
  1137.  asr.l #1,d1    ; (x*x-a)/2
  1138.  divs d0,d1    ; (x*x-a)/2x
  1139.  sub.w d1,d0    ; second approx
  1140.  bgt .stillnot0
  1141.  move.w #1,d0
  1142. .stillnot0
  1143.  
  1144.  move.w d0,d1
  1145.  muls d1,d1
  1146.  sub.l d2,d1
  1147.  asr.l #1,d1
  1148.  divs d0,d1
  1149.  sub.w d1,d0    ; second approx
  1150.  bgt .stillnot02
  1151.  move.w #1,d0
  1152. .stillnot02
  1153.  
  1154.  move.w d0,distaway
  1155. .nochange:
  1156.  
  1157.  rts
  1158.  
  1159.  
  1160. counterer: dc.w 0
  1161. CosRet: dc.w 0
  1162. SinRet: dc.w 0
  1163.  
  1164. HeadTowardsAng:
  1165.  
  1166.  move.w newx,d1
  1167.  sub.w oldx,d1
  1168.  move.w d1,xdiff
  1169.  move.w newz,d2
  1170.  sub.w oldz,d2
  1171.  move.w d2,zdiff
  1172.  muls d1,d1
  1173.  muls d2,d2
  1174.  move.w #0,d0
  1175.  add.l d1,d2
  1176.  seq GotThere
  1177.  beq .nochange
  1178.  
  1179.  move.w #31,d0
  1180. .findhigh
  1181.  btst d0,d2
  1182.  bne .foundhigh
  1183.  dbra d0,.findhigh
  1184. .foundhigh
  1185.  asr.w #1,d0
  1186.  clr.l d3
  1187.  bset d0,d3
  1188.  move.l d3,d0
  1189.  
  1190.  move.w d0,d1
  1191.  muls d1,d1    ; x*x
  1192.  sub.l d2,d1    ; x*x-a
  1193.  asr.l #1,d1    ; (x*x-a)/2
  1194.  divs d0,d1    ; (x*x-a)/2x
  1195.  sub.w d1,d0    ; second approx
  1196.  bgt .stillnot0
  1197.  move.w #1,d0
  1198. .stillnot0
  1199.  
  1200.  move.w d0,d1
  1201.  muls d1,d1
  1202.  sub.l d2,d1
  1203.  asr.l #1,d1
  1204.  divs d0,d1
  1205.  sub.w d1,d0    ; second approx
  1206.  bgt .stillnot02
  1207.  move.w #1,d0
  1208. .stillnot02
  1209.  
  1210.  move.w d0,d1
  1211.  muls d1,d1
  1212.  sub.l d2,d1
  1213.  asr.l #1,d1
  1214.  divs d0,d1
  1215.  sub.w d1,d0    ; second approx
  1216.  bgt .stillnot03
  1217.  move.w #1,d0
  1218. .stillnot03
  1219.  
  1220.  
  1221. ; d0=perpdist
  1222.  
  1223.  cmp.w Range,d0
  1224.  sle GotThere
  1225.  bgt .faraway
  1226.  
  1227.  move.w oldx,newx
  1228.  move.w oldz,newz
  1229.  bra .nochange
  1230.  
  1231.  move.w xdiff,d1
  1232.  move.w zdiff,d2
  1233.  muls Range,d1
  1234.  muls Range,d2
  1235.  addq #3,d0
  1236.  divs d0,d1
  1237.  divs d0,d2
  1238.  subq #3,d0
  1239.  neg.w d1
  1240.  neg.w d2
  1241.  add.w d1,newx
  1242.  add.w d2,newz
  1243.  tst.b canshove
  1244.  beq .nochange
  1245.  move.w PLR1_opushx(pc),d1
  1246.  add.w PLR2_opushx(pc),d1
  1247.  sub.w d1,newx
  1248.  move.w PLR1_opushz(pc),d1
  1249.  add.w PLR2_opushz(pc),d1
  1250.  sub.w d1,newz
  1251.  move.w xdiff,d1
  1252.  move.w zdiff,d2
  1253.  move.w Range,d3
  1254.  sub.w d0,d3
  1255.  muls d3,d1
  1256.  muls d3,d2
  1257.  divs d0,d1
  1258.  divs d0,d2
  1259.  move.w d1,shovex
  1260.  move.w d2,shovez
  1261.  bra .nochange
  1262.  
  1263. .faraway:
  1264.  
  1265.  move.w speed,d3
  1266.  add.w Range,d3
  1267.  cmp.w d0,d3
  1268.  blt.s .notoofast
  1269.  move.w d0,d3
  1270.  st GotThere
  1271. .notoofast:
  1272.  sub.w Range,d3
  1273.  
  1274.  move.w xdiff,d1
  1275.  muls d3,d1
  1276.  divs d0,d1
  1277.  move.w zdiff,d2
  1278.  muls d3,d2
  1279.  divs d0,d2
  1280.  add.w oldx,d1
  1281.  move.w d1,newx
  1282.  add.w oldz,d2
  1283.  move.w d2,newz
  1284.  
  1285. .nochange:
  1286.  
  1287.  tst.w d0
  1288.  beq.s nocossin
  1289.  
  1290.  add.w #1,d0
  1291.  move.w xdiff,d1
  1292.  swap d1
  1293.  clr.w d1
  1294.  asr.l #1,d1
  1295.  divs d0,d1
  1296.  move.w d1,SinRet
  1297.  move.w zdiff,d1
  1298.  swap d1
  1299.  clr.w d1
  1300.  asr.l #1,d1
  1301.  divs d0,d1
  1302.  move.w d1,CosRet
  1303.  
  1304.  move.w SinRet,d0
  1305.  move.w #0,d2
  1306.  move.l #SineTable,a2
  1307.  lea 2048(a2),a3
  1308.  move.w #3,d5
  1309.  move.w #2048,d6
  1310. findanglop:
  1311.  
  1312.  move.w (a2,d2.w*2),d3
  1313.  move.w (a3,d2.w*2),d4
  1314.  muls d0,d4
  1315.  muls d1,d3
  1316.  sub.l d3,d4
  1317.  blt.s subang
  1318.  add.w d6,d2
  1319.  add.w d6,d2
  1320. subang:
  1321.  sub.w d6,d2
  1322.  and.w #4095,d2
  1323.  asr.w #1,d6
  1324.  dbra d5,findanglop
  1325.  add.w d2,d2
  1326.  move.w d2,AngRet
  1327.  
  1328. nocossin:
  1329.  
  1330.  rts
  1331.  
  1332. AngRet: dc.w 0
  1333. Range: dc.w 0
  1334. GotThere: dc.w 0
  1335. shovex: dc.w 0
  1336. shovez: dc.w 0
  1337. canshove: dc.w 0
  1338. PLR2_pushx: dc.l 0
  1339. PLR2_pushz: dc.l 0
  1340. PLR2_opushx: dc.l 0
  1341. PLR2_opushz: dc.l 0
  1342. PLR1_pushx: dc.l 0
  1343. PLR1_pushz: dc.l 0
  1344. PLR1_opushx: dc.l 0
  1345. PLR1_opushz: dc.l 0
  1346.  
  1347. CheckHit:
  1348.  move.w newx,d0
  1349.  sub.w oldx,d0
  1350.  move.w newz,d1
  1351.  sub.w oldz,d1
  1352.  muls d1,d1
  1353.  muls d0,d0
  1354.  add.l d0,d1
  1355.  cmp.l d2,d1
  1356.  slt hitwall
  1357.  rts
  1358.  
  1359. GetNextCPt:
  1360.  cmp.w d0,d1
  1361.  beq.s noneedforhassle
  1362.  muls #100,d0
  1363.  ext.l d1
  1364.  add.l d1,d0
  1365.  move.l a0,-(a7)
  1366.  lea ControlPts,a0
  1367.  move.b (a0,d0.w),d0
  1368.  ext.w d0
  1369.  move.l (a7)+,a0
  1370. noneedforhassle:
  1371.  rts
  1372.  
  1373. FromRoom: dc.l 0
  1374. ToRoom: dc.l 0
  1375. CanSee: dc.w 0
  1376. Facedir: dc.w 0
  1377.  
  1378.  even
  1379.  
  1380. CanItBeSeenAng:
  1381.  movem.l d0-d7/a0-a6,-(a7)
  1382.  
  1383.  move.w Facedir,d0
  1384.  move.l #SineTable,a0
  1385.  add.w d0,a0
  1386.  move.w (a0),d0
  1387.  move.w 2048(a0),d1
  1388.  move.w Targetx,d2
  1389.  sub.w Viewerx,d2
  1390.  move.w Targetz,d3
  1391.  sub.w Viewerz,d3
  1392.  muls d1,d2
  1393.  muls d0,d3
  1394.  sub.l d3,d2
  1395.  bgt.s ItMightBeSeen
  1396.  clr.b CanSee
  1397.  movem.l (a7)+,d0-a7/a0-a6
  1398.  rts
  1399. ItMightBeSeen:
  1400.  
  1401.  move.l ToRoom,a0
  1402.  move.w (a0),d0
  1403.  move.l FromRoom,a0
  1404.  adda.w #ToListOfGraph,a0
  1405.  bra.s InList
  1406.  
  1407. Viewerx: dc.l 0
  1408. Viewerz: dc.l 0
  1409. Targetx: dc.l 0
  1410. Targetz: dc.l 0
  1411. ViewerTop: dc.b 0
  1412. TargetTop: dc.b 0 
  1413. Viewery: dc.w 0
  1414. Targety: dc.w 0
  1415.  
  1416.   even
  1417.  
  1418. insameroom:
  1419.  st CanSee
  1420.  move.b ViewerTop,d0
  1421.  move.b TargetTop,d1
  1422.  eor.b d0,d1
  1423.  bne outlist
  1424.  movem.l (a7)+,d0-d7/a0-a6
  1425.  rts
  1426.  
  1427. CanItBeSeen:
  1428.  
  1429.  movem.l d0-d7/a0-a6,-(a7)
  1430.  move.l ToRoom,a1
  1431.  move.w (a1),d0
  1432.  move.l FromRoom,a0
  1433.  cmp.l a0,a1
  1434.  beq.s insameroom
  1435.  
  1436.  adda.w #ToListOfGraph,a0
  1437.  
  1438. InList:
  1439.  move.w (a0),d1
  1440.  tst.w d1
  1441.  blt outlist
  1442.  move.l ZoneGraphAdds,a1
  1443.  move.l (a1,d1.w*8),a1
  1444.  add.l LEVELGRAPHICS,a1
  1445.  
  1446.  adda.w #8,a0
  1447.  cmp.w (a1),d0
  1448.  beq isinlist
  1449.  
  1450.  bra.s InList
  1451.  
  1452. isinlist:
  1453. ; We have found the dest room in the
  1454. ; list of rooms visible from the
  1455. ; source room.
  1456.  
  1457. ; Do line of sight!
  1458.  
  1459.  st CanSee
  1460.  
  1461.  move.l Points,a2
  1462.  move.w Targetx,d1
  1463.  move.w Targetz,d2
  1464.  sub.w Viewerx,d1
  1465.  sub.w Viewerz,d2
  1466.  
  1467.  moveq #0,d3
  1468.  move.w -6(a0),d3
  1469.  blt nomorerclips
  1470.  move.l LEVELCLIPS,a1
  1471.  lea (a1,d3.l*2),a1
  1472.  move.l a1,clipstocheck
  1473. checklcliploop:
  1474.  tst.w (a1)
  1475.  blt nomorelclips
  1476.  
  1477.  move.w (a1),d0
  1478.  blt.s noleftone
  1479.  move.l (a2,d0.w*4),d3
  1480.  move.w d3,d4
  1481.  sub.w Viewerz,d4
  1482.  swap d3
  1483.  sub.w Viewerx,d3
  1484.  muls d2,d3
  1485.  muls d1,d4
  1486.  sub.l d3,d4
  1487.  ble outlist
  1488.  
  1489. noleftone:
  1490.  
  1491.  addq #2,a1
  1492.  
  1493.  bra checklcliploop
  1494.  
  1495. nomorelclips:
  1496.  
  1497.  addq #2,a1
  1498.  
  1499. checkrcliploop:
  1500.  tst.w (a1)
  1501.  blt nomorerclips
  1502.  
  1503.  move.w (a1),d0
  1504.  blt.s norightone
  1505.  move.l (a2,d0.w*4),d3
  1506.  move.w d3,d4
  1507.  sub.w Viewerz,d4
  1508.  swap d3
  1509.  sub.w Viewerx,d3
  1510.  muls d2,d3
  1511.  muls d1,d4
  1512.  sub.l d3,d4
  1513.  bge outlist
  1514.  
  1515. norightone:
  1516.  addq #2,a1
  1517.  
  1518.  bra checkrcliploop
  1519.  
  1520.  
  1521. nomorerclips:
  1522.  
  1523. ; No clipping points in the way; got to do the
  1524. ; vertical working out now.
  1525.  
  1526.  move.w Targetx,d0
  1527.  move.w Targetz,d1
  1528.  sub.w Viewerx,d0
  1529.  sub.w Viewerz,d1
  1530.  move.l FromRoom,a5
  1531.  move.l FloorLines,a1
  1532.  move.b ViewerTop,d2
  1533.  move.w Targety,d7
  1534.  sub.w Viewery,d7
  1535.  
  1536.  
  1537. GoThroughZones:
  1538.  move.l a5,a0
  1539.  adda.w ToExitList(a0),a0
  1540.  
  1541. FindWayOut:
  1542.  move.w (a0)+,d5
  1543.  blt outlist
  1544.  asl.w #4,d5
  1545.  lea (a1,d5.w),a2
  1546.  
  1547.  move.w (a2),d3
  1548.  move.w 2(a2),d4
  1549.  sub.w Viewerx,d3
  1550.  sub.w Viewerz,d4
  1551.  move.w d3,d5
  1552.  move.w d4,d6
  1553.  muls d1,d3
  1554.  muls d0,d4
  1555.  sub.l d3,d4
  1556.  ble FindWayOut
  1557.  
  1558.  add.w 4(a2),d5
  1559.  add.w 6(a2),d6
  1560.  muls d0,d6
  1561.  muls d1,d5
  1562.  sub.l d5,d6
  1563.  bge FindWayOut
  1564.  
  1565.  tst.w 8(a2)
  1566.  blt outlist
  1567.  
  1568. ; Here is the exit from the room. Calculate the height at which
  1569. ; we meet it.
  1570.  
  1571.  move.w Targetx,d3
  1572.  move.w Targetz,d4
  1573.  sub.w (a2),d3
  1574.  sub.w 2(a2),d4
  1575.  muls 4(a2),d4
  1576.  muls 6(a2),d3
  1577.  sub.l d3,d4    ; positive
  1578.  
  1579.  move.w Viewerx,d5
  1580.  move.w Viewerz,d6
  1581.  sub.w (a2),d5
  1582.  sub.w 2(a2),d6
  1583.  muls 4(a2),d6
  1584.  muls 6(a2),d5
  1585.  sub.l d6,d5    ; positive
  1586.  
  1587.  divs 10(a2),d4
  1588.  divs 10(a2),d5
  1589.  
  1590.  add.w d5,d4
  1591.  beq.s sameheight
  1592.  muls d7,d5
  1593.  divs d4,d5
  1594. sameheight:
  1595.  add.w Viewery,d5    ; height at which we cross wall
  1596.  
  1597.  ext.l d5
  1598.  asl.l #7,d5
  1599.  
  1600.  tst.b d2
  1601.  beq.s comparewithbottom
  1602.  
  1603.  cmp.l ToUpperRoof(a5),d5
  1604.  blt outlist
  1605.  cmp.l ToUpperFloor(a5),d5
  1606.  bgt outlist
  1607.  bra.s madeit
  1608.  
  1609. comparewithbottom:
  1610.  cmp.l ToZoneRoof(a5),d5
  1611.  blt outlist
  1612.  cmp.l ToZoneFloor(a5),d5
  1613.  bgt outlist
  1614. madeit:
  1615.  st donessomething
  1616.  
  1617.  moveq #0,d3
  1618.  move.w 8(a2),d3
  1619.  move.l ZoneAdds,a3
  1620.  move.l (a3,d3.w*4),a5
  1621.  add.l LEVELDATA,a5
  1622.  
  1623.  clr.b d2
  1624.  cmp.l ToZoneFloor(a5),d5
  1625.  bgt outlist
  1626.  cmp.l ToZoneRoof(a5),d5
  1627.  bgt.s GotIn
  1628.  st d2
  1629.  cmp.l ToUpperFloor(a5),d5
  1630.  bgt outlist
  1631.  cmp.l ToUpperRoof(a5),d5
  1632.  blt outlist
  1633.  
  1634. GotIn:
  1635.  
  1636.  cmp.l ToRoom,a5
  1637.  bne GoThroughZones
  1638.  
  1639.  move.b TargetTop,d3
  1640.  eor.b d2,d3
  1641.  bne outlist
  1642.  
  1643.  movem.l (a7)+,d0-d7/a0-a6
  1644.  rts
  1645.  
  1646. clipstocheck: dc.l 0
  1647. donessomething: dc.w 0
  1648.  
  1649. outlist:
  1650.  clr.b CanSee
  1651.  movem.l (a7)+,d0-d7/a0-a6
  1652.  rts
  1653.  
  1654.  
  1655. FindCollisionPt:
  1656.  movem.l d0-a7/a0-a6,-(a7)
  1657.  
  1658.  move.w Targetx,d0
  1659.  move.w Targetz,d1
  1660.  sub.w Viewerx,d0
  1661.  sub.w Viewerz,d1
  1662.  move.l FromRoom,a5
  1663.  move.l FloorLines,a1
  1664.  move.b ViewerTop,d2
  1665.  move.w Targety,d7
  1666.  sub.w Viewery,d7
  1667.  
  1668.  
  1669. .GoThroughZones:
  1670.  move.l a5,a0
  1671.  adda.w ToExitList(a0),a0
  1672.  
  1673. .FindWayOut:
  1674.  move.w (a0)+,d5
  1675.  blt outlist
  1676.  asl.w #4,d5
  1677.  lea (a1,d5.w),a2
  1678.  
  1679.  move.w (a2),d3
  1680.  move.w 2(a2),d4
  1681.  sub.w Viewerx,d3
  1682.  sub.w Viewerz,d4
  1683.  move.w d3,d5
  1684.  move.w d4,d6
  1685.  muls d1,d3
  1686.  muls d0,d4
  1687.  sub.l d3,d4
  1688.  ble .FindWayOut
  1689.  
  1690.  add.w 4(a2),d5
  1691.  add.w 6(a2),d6
  1692.  muls d0,d6
  1693.  muls d1,d5
  1694.  sub.l d5,d6
  1695.  bge .FindWayOut
  1696.  
  1697.  
  1698. ; Here is the exit from the room. Calculate the height at which
  1699. ; we meet it.
  1700.  
  1701.  move.w Targetx,d3
  1702.  move.w Targetz,d4
  1703.  sub.w (a2),d3
  1704.  sub.w 2(a2),d4
  1705.  muls 4(a2),d4
  1706.  muls 6(a2),d3
  1707.  sub.l d3,d4    ; positive
  1708.  
  1709.  move.w Viewerx,d5
  1710.  move.w Viewerz,d6
  1711.  sub.w (a2),d5
  1712.  sub.w 2(a2),d6
  1713.  muls 4(a2),d6
  1714.  muls 6(a2),d5
  1715.  sub.l d6,d5    ; positive
  1716.  
  1717.  divs 10(a2),d4
  1718.  divs 10(a2),d5
  1719.  
  1720.  move.w d5,d6
  1721.  add.w d5,d4
  1722.  beq.s .sameheight
  1723.  muls d7,d5
  1724.  divs d4,d5
  1725. .sameheight:
  1726.  add.w Viewery,d5    ; height at which we cross wall
  1727.  
  1728.  ext.l d5
  1729.  asl.l #7,d5
  1730.  
  1731.  moveq #0,d3
  1732.  move.w 8(a2),d3
  1733.  blt foundpt
  1734.  move.l ZoneAdds,a3
  1735.  move.l (a3,d3.w*4),a5
  1736.  add.l LEVELDATA,a5
  1737.  
  1738.  clr.b d2
  1739.  cmp.l ToZoneFloor(a5),d5
  1740.  bgt foundpt
  1741.  cmp.l ToZoneRoof(a5),d5
  1742.  bgt.s .GotIn
  1743.  st d2
  1744.  cmp.l ToUpperFloor(a5),d5
  1745.  bgt foundpt
  1746.  cmp.l ToUpperRoof(a5),d5
  1747.  blt foundpt
  1748.  
  1749. .GotIn:
  1750.  
  1751.  bra .GoThroughZones
  1752.  
  1753.  tst.w d4
  1754.  beq.s foundpt
  1755.  muls d6,d0
  1756.  divs d4,d0
  1757.  muls d6,d1
  1758.  divs d4,d1
  1759.  add.w Viewerx,d0
  1760.  add.w Viewerz,d1
  1761.  move.w d0,Targetx
  1762.  move.w d1,Targetz
  1763.  move.l d5,Targety
  1764.  
  1765. foundpt:
  1766.  
  1767.  movem.l (a7)+,d0-a7/a0-a6
  1768.  rts
  1769.  
  1770. GetRand:
  1771.  move.w Rand1,d0
  1772.  add.w #29,d0
  1773.  eor.w #$5f37,d0
  1774.  neg.w d0
  1775.  rol.w #5,d0
  1776.  move.w d0,Rand1
  1777.  rts
  1778.  
  1779. Rand1: dc.w 234
  1780.  
  1781. GoInDirection:
  1782.  move.l #SineTable,a0
  1783.  lea (a0,d0.w),a0
  1784.  move.w (a0),d1
  1785.  move.w 2048(a0),d2
  1786.  muls speed,d1
  1787.  add.l d1,d1
  1788.  muls speed,d2
  1789.  add.l d2,d2
  1790.  swap d1
  1791.  swap d2
  1792.  add.w oldx,d1
  1793.  add.w oldz,d2
  1794.  move.w d1,newx
  1795.  move.w d2,newz
  1796.  rts
  1797.  
  1798. CollideFlags: dc.l 0
  1799.  
  1800. Collision:
  1801.  
  1802.  move.l ObjectData,a0
  1803.  move.w CollId,d0
  1804.  asl.w #6,d0
  1805.  move.b 16(a0,d0.w),d0
  1806.  ext.w d0
  1807.  
  1808.  sub.w #64,a0
  1809.  move.l ObjectPoints,a1
  1810.  move.l #ColBoxTable,a2
  1811.  lea  (a2,d0.w*8),a3
  1812.  
  1813.  move.l CollideFlags,d7
  1814.  move.b StoodInTop,d6
  1815.  move.l newy,d4
  1816.  move.l d4,d5
  1817.  add.l thingheight,d5
  1818.  asr.l #7,d4
  1819.  asr.l #7,d5
  1820.  clr.b hitwall
  1821.  
  1822. checkcol:
  1823.  add.w #64,a0
  1824.  
  1825.  move.w (a0),d0
  1826.  blt checkedallcol
  1827.  
  1828.  cmp.w CollId,d0
  1829.  beq.s checkcol
  1830.  
  1831.  tst.w 12(a0)
  1832.  blt.s checkcol
  1833.  
  1834.  tst.b numlives(a0)
  1835.  beq.s checkcol
  1836.  
  1837.  move.b ObjInTop(a0),d1
  1838.  eor.b d6,d1
  1839.  bne checkcol
  1840.  
  1841.  moveq #0,d3
  1842.  move.b 16(a0),d3
  1843.  blt checkcol
  1844.  
  1845.  btst d3,d7
  1846.  beq checkcol
  1847.  
  1848.  move.w 4(a0),d1
  1849.  sub.w 2(a2,d3.w*8),d1
  1850.  cmp.w d1,d5
  1851.  blt checkcol
  1852.  add.w 4(a2,d3.w*8),d1
  1853.  cmp.w d1,d4
  1854.  bgt checkcol
  1855.  
  1856.  move.w (a1,d0.w*8),d1
  1857.  move.w 4(a1,d0.w*8),d2
  1858.  sub.w newx,d1
  1859.  bge.s .xnoneg
  1860.  neg.w d1
  1861. .xnoneg:
  1862.  sub.w newz,d2
  1863.  bge.s .znoneg
  1864.  neg.w d2
  1865. .znoneg:
  1866.  cmp.w d1,d2
  1867.  ble.s .checkx
  1868.  sub.w (a3),d2
  1869.  cmp.w (a2,d3.w*8),d2
  1870.  bgt checkcol
  1871.  st hitwall
  1872.  bra checkedallcol
  1873. .checkx:
  1874.  sub.w (a3),d1
  1875.  cmp.w (a2,d3.w*8),d1
  1876.  bgt checkcol
  1877.  
  1878.  move.w (a1,d0.w*8),d1
  1879.  move.w 4(a1,d0.w*8),d2
  1880.  move.w d1,d6
  1881.  move.w d2,d7
  1882.  sub.w newx,d6
  1883.  sub.w newz,d7
  1884.  muls d6,d6
  1885.  muls d7,d7
  1886.  add.l d6,d7
  1887.  sub.w oldx,d1
  1888.  sub.w oldz,d2
  1889.  muls d1,d1
  1890.  muls d2,d2
  1891.  add.l d1,d2
  1892.  cmp.l d2,d7
  1893.  bgt checkcol
  1894.  
  1895.  st hitwall
  1896.  bra checkedallcol
  1897.  
  1898. ; bra checkcol
  1899.  
  1900. checkedallcol:
  1901.  rts
  1902.  
  1903. ColBoxTable:
  1904.  
  1905. ; red scurrying alien
  1906.  dc.w 40,60,120,0
  1907. ; Medipack
  1908.  dc.w 40,20,40,0
  1909. ; Bullet
  1910.  dc.w 40,20,40,0
  1911. ; Gun
  1912.  dc.w 40,20,40,0
  1913. ; Key
  1914.  dc.w 40,20,40,0
  1915. ; PLayer1
  1916.  dc.w 40,40,80,0
  1917. ;Robot
  1918.  dc.w 40,50,100,0
  1919. ;?
  1920.  dc.w 40,20,40,0
  1921. ; Flying Nasty
  1922.  dc.w 80,60,120,0
  1923. ; Ammo
  1924.  dc.w 40,20,40,0
  1925. ; Barrel
  1926.  dc.w 40,30,60,0
  1927. ;PlAYER2
  1928.  dc.w 40,40,80,0
  1929. ; Mutant Marine
  1930.  dc.w 40,40,80,0
  1931. ; worm
  1932.  dc.w 80,60,120,0
  1933. ; huge red thing
  1934.  dc.w 160,100,200,0
  1935. ; small red thing
  1936.  dc.w 80,50,100,0
  1937. ; tree
  1938.  dc.w 80,60,120,0
  1939. ; eyeball
  1940.  dc.w 40,30,60,0
  1941. ; Tough Marine
  1942.  dc.w 40,40,80,0
  1943. ; ShotGun Marine
  1944.  dc.w 40,40,80,0
  1945.  
  1946. FromZone: dc.w 0
  1947. OKTEL: dc.w 0
  1948. floortemp: dc.l 0
  1949.  
  1950. CheckTeleport:
  1951.  clr.b OKTEL
  1952.  move.w FromZone,d0
  1953.  move.l ZoneAdds,a2
  1954.  move.l (a2,d0.w*4),a2
  1955.  add.l LEVELDATA,a2
  1956.  tst.w ToTelZone(a2)
  1957.  bge.s ITSATEL
  1958.  rts
  1959.  
  1960. ITSATEL:
  1961.  move.l ToZoneFloor(a2),floortemp
  1962.  move.w ToTelZone(a2),d0
  1963.  move.l ZoneAdds,a3
  1964.  move.l (a3,d0.w*4),a3
  1965.  add.l LEVELDATA,a3
  1966.  move.l ToZoneFloor(a3),d0
  1967.  sub.l floortemp,d0
  1968.  move.l d0,floortemp
  1969.  add.l d0,newy 
  1970.  move.w ToTelX(a2),newx
  1971.  move.w ToTelZ(a2),newz
  1972.  move.l #%1111111111111111111,CollideFlags
  1973.  movem.l a0/a1/a2,-(a7)
  1974.  bsr Collision
  1975.  movem.l (a7)+,a0/a1/a2
  1976.  
  1977.  move.l floortemp,d0
  1978.  sub.l d0,newy
  1979.  
  1980.  tst.b hitwall
  1981.  seq OKTEL
  1982.  beq.s .teleport
  1983.  rts
  1984. .teleport:
  1985.  move.w ToTelZone(a2),d0
  1986.  move.l ZoneAdds,a2
  1987.  move.l (a2,d0.w*4),a2
  1988.  add.l LEVELDATA,a2
  1989.  move.l a2,objroom
  1990.  
  1991.  rts
  1992.  
  1993. FindCloseRoom:
  1994.  ; d0 is distance.
  1995.  
  1996.  move.w 4(a0),d1
  1997.  ext.l d1
  1998.  asl.l #7,d1
  1999.  move.l d1,oldy
  2000.  move.l d1,newy
  2001.  
  2002.  move.w (a0),d1
  2003.  move.l ObjectPoints,a1
  2004.  lea (a1,d1.w*8),a1
  2005.  move.w (a1),oldx 
  2006.  move.w 4(a1),oldz
  2007.  
  2008.  move.w 12(a0),d2
  2009.  move.l ZoneAdds,a5
  2010.  move.l (a5,d2.w*4),d2
  2011.  add.l LEVELDATA,d2
  2012.  move.l d2,objroom
  2013.  
  2014.  move.w THISPLRxoff,newx
  2015.  move.w THISPLRzoff,newz
  2016.  move.w d0,speed
  2017.  movem.l a0/a1,-(a7)
  2018.  jsr HeadTowards
  2019.  movem.l (a7)+,a0/a1
  2020.  
  2021.  move.w newx,d0
  2022.  sub.w oldx,d0
  2023.  move.w oldz,d1
  2024.  sub.w newz,d1
  2025.  
  2026.  move.w d1,xd
  2027.  move.w d0,zd
  2028.  
  2029.  move.l #100000,StepUpVal
  2030.  move.l #100000,StepDownVal
  2031.  move.w #0,thingheight
  2032.  
  2033.  st exitfirst
  2034.  
  2035.  add.w oldx,d1
  2036.  add.w oldz,d0
  2037.  move.w d1,newx
  2038.  move.w d0,newz
  2039.  movem.l d0-d7/a0-a6,-(a7)
  2040.  jsr MoveObject
  2041.  movem.l (a7)+,d0-d7/a0-a6
  2042.  
  2043.  move.l #RoomPath,a2
  2044.  move.l #possclose,a3
  2045.  move.w 12(a0),(a3)+
  2046.  
  2047. putinmore:
  2048.  move.w (a2)+,(a3)+
  2049.  bge.s putinmore
  2050.  subq #2,a3
  2051.  
  2052.  move.w oldx,d0
  2053.  sub.w xd,d0
  2054.  move.w oldz,d1
  2055.  sub.w zd,d1
  2056.  move.w d0,newx
  2057.  move.w d1,newz    
  2058.  
  2059.  movem.l d0-d7/a0-a6,-(a7)
  2060.  jsr MoveObject
  2061.  movem.l (a7)+,d0-d7/a0-a6
  2062.  
  2063.  move.l #RoomPath,a2
  2064.  
  2065. putinmore2:
  2066.  move.w (a2)+,d0
  2067.  move.w d0,(a3)+
  2068.  tst.w d0
  2069.  bge.s putinmore2
  2070.  
  2071. ; ok a3 points at list of rooms passed through.
  2072.  move.w #-1,(a3)+
  2073.  
  2074.  
  2075.  move.w 12(a0),d7
  2076.  
  2077.  move.l endoflist,a3
  2078. FINDCLOSELOOP:
  2079.  move.l #possclose,a2
  2080.  move.w -(a3),d0
  2081.  blt foundclose
  2082.  
  2083. findinner
  2084.  move.w (a2)+,d1
  2085.  blt.s outin
  2086.  cmp.w d0,d1
  2087.  bne.s findinner
  2088.  move.w d0,d7
  2089. outin:
  2090.  
  2091.  bra.s FINDCLOSELOOP
  2092.  
  2093. foundclose:
  2094.  
  2095.  move.w d7,GraphicRoom(a0)
  2096.  
  2097.  rts
  2098.  
  2099. xd: dc.w 0
  2100. zd: dc.w 0
  2101.  
  2102. possclose:
  2103.  ds.w 100